//
//  ImageTableViewCell.m
//  Koala_Fm
//
//  Created by dllo on 16/1/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ImageTableViewCell.h"

@implementation ImageTableViewCell

- (void)dealloc
{
    [_headImage release];//头像
    [_timeLable release];// 时间
    [_nameLable release];;//名字
    [_button release];
    [_texLable release];//文字
    [_imag release];//图片
    [_imageTable release];
    [_funnyLable release];// 搞笑
    [_hotLable release];
    [_caiLable release];
    [_commentLable release];
    [_widthD release];
    [_widthE release];
    [_heightD release];
    [_heightE release];
    [_judge release];
    [_imager release];
    [_zanLable release];
    [_caiLable release];
    [_relayLable release];
    [_reviewLable release];
    [_zanImage release];
    [_relayImage release];
    [_reviewImage release];
    [_caiImage release];
    [_xLable release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //
        self.headImage = [[UIImageView alloc]init];
//        _headImage.backgroundColor = [UIColor redColor];
        // 切圆
        _headImage.layer.cornerRadius = 25;
        _headImage.clipsToBounds = YES;
        [self.contentView addSubview:_headImage];
        [_headImage release];
        //
        self.timeLable = [[UILabel alloc]init];
//                _timeLable.backgroundColor = [UIColor yellowColor];
        _timeLable.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:_timeLable];
        [_timeLable release];
        //
        _nameLable.font = [UIFont systemFontOfSize:15];
        self.nameLable = [[UILabel alloc]init];
//                _nameLable.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_nameLable];
        [_nameLable release];
        //
        self.texLable = [[UILabel alloc]init];
//        self.texLable.backgroundColor = [UIColor greenColor];
        // texLable 行数为0
        self.texLable.numberOfLines = 0;
        [self.contentView addSubview:_texLable];
        [_texLable release];
        //
        self.imag = [[UIImageView alloc]init];
//        self.imag.backgroundColor = [UIColor redColor];
        
        [self.contentView addSubview:_imag];
        [_imag release];
        //
        self.zanLable = [[UILabel alloc]init];
        //        _zanLable.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_zanLable];
        [_zanLable release];
        //
        self.caiLable = [[UILabel alloc]init];
        //        _caiLable.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_caiLable];
        [_caiLable release];
        //
        self.relayLable = [[UILabel alloc]init];
        //        _relayLable.backgroundColor =[UIColor blueColor];
        [self.contentView addSubview:_relayLable];
        [_relayLable release];
        //
        self.reviewLable = [[UILabel alloc]init];
        //        _reviewLable.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_reviewLable];
        [_reviewLable release ];
        //
        self.zanImage = [[UIImageView alloc]init];
        //        _zanImage.backgroundColor = [UIColor yellowColor];
        
        [self.contentView addSubview:_zanImage];
        [_zanImage release];
        //
        self.relayImage = [[UIImageView alloc]init];
        //        _relayImage.backgroundColor = [UIColor blueColor];
        [self.contentView addSubview:_relayImage];
        [_relayImage release];
        //
        self.reviewImage = [[UIImageView alloc]init];
        //        _reviewImage.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_reviewImage];
        [_reviewImage release];
        //
        self.caiImage = [[UIImageView alloc]init];
        //        _caiImage.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_caiImage];
        [_caiImage release];
        //
        self.xLable = [[UILabel alloc]init];
//        _xLable.backgroundColor = [UIColor grayColor];
        [self.contentView addSubview:_xLable];
        [_xLable release];

    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _headImage.frame =CGRectMake(5, 5, 50, 50);
    _nameLable.frame = CGRectMake(60, 5, 150, 20);
    _timeLable.frame = CGRectMake(60, 25, 150, 20);
    CGFloat texth = [[self class]heightWithText:_texLable.text];
    //判断是否是动图
    CGFloat h;
    if (_judge != nil) {
        h = [[self class] heightWithHeight:_heightE  width:_widthE];
    }
    else{
        h = [[self class] heightWithHeight:_heightD  width:_widthD];
    }
    _texLable.frame =CGRectMake(10, 60, self.contentView.frame.size.width - 40, texth);
    _imag.frame = CGRectMake(10, 60 + 5 + texth, self.contentView.frame.size.width - 20, h);
    
    _xLable.frame = CGRectMake(5, h + texth + 10 + 85 + 1, self.contentView.frame.size.width - 10,  1);
    _zanImage.frame = CGRectMake(20, h + texth + 10 + 60 + 30,30 , 30);
    
    _zanLable.frame = CGRectMake(50, h + 10 + texth + 60 + 30, 45 , 30);
    _caiImage.frame = CGRectMake(100, h + 10 + texth + 60 + 30,30, 30);
    _caiLable.frame = CGRectMake(135 , h + 10 + texth + 60 + 30 ,45 , 30);
    _relayImage.frame = CGRectMake(180,h + 10 + texth + 60 + 30 , 30,30 );
    
    _relayLable.frame = CGRectMake(215, h + 10 + texth + 60 + 30, 45, 30);
    _reviewImage.frame = CGRectMake(270, h + 10 + texth + 60 + 30, 30, 30);
    _reviewLable.frame = CGRectMake(300, h + 100 + texth , 45, 30);
    
}
// 自适应高度
+(CGFloat)heightWithText:(NSString *)text{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(355, 1000);
    CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
// 图片自适应高度
+(CGFloat)heightWithHeight:(NSNumber *)height width:(NSNumber *)width{
    CGFloat h;
    if ([width floatValue] != 0) {
        h = [height floatValue] * 355 / [width floatValue];
    }
    
    return h;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
